package logic

import (
	"context"
	"goods_srv/modile/mysql"

	"goods_srv/goods"
	"goods_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type FindGoodsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewFindGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FindGoodsLogic {
	return &FindGoodsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *FindGoodsLogic) FindGoods(in *goods.FindGoodsRequest) (*goods.FindGoodsResponse, error) {
	// todo: 查询商品是否存

	g := mysql.Goods2{}

	err := g.FindGoods(int(in.GoodsId))
	if err != nil {
		logx.Error("查询失败", err)
		return nil, err
	}

	return &goods.FindGoodsResponse{
		GoodsTitle:  g.GoodsTitle,
		GoodsPrice:  g.GoodsPrice,
		GoodsStock:  g.GoodsStock,
		GoodsStatus: int64(g.GoodsStatus),
		GoodsCover:  g.GoodsCover,
		GoodsId:     int64(g.ID),
	}, nil
}
